package com.mabs.ground.client.module.mod2.activity;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.mabs.ground.client.common.ClientFactory;
import com.mabs.ground.client.common.MyAbstractActivity;
import com.mabs.ground.client.module.mod1.place.HelloPlace;
import com.mabs.ground.client.module.mod2.place.GoodbyePlace;
import com.mabs.ground.client.module.mod2.view.GoodbyeView;

/**
 * @author <a href="Email: mohamedarbi.benslimane@allence-tunisie.com">Ben
 *         Slimane Arbi</a>
 * @version 1.0
 * @since 1.0 - 25 juil. 2014 - 20:03:30
 */
public class GoodbyeActivity extends MyAbstractActivity {
	// Used to obtain views, eventBus, placeController
	// Alternatively, could be injected via GIN
	// Name that will be appended to "Hello,"
	private String name;

	public GoodbyeActivity(GoodbyePlace place, ClientFactory clientFactory) {
		super(clientFactory);
		this.name = place.getGoodbyeName();
		display = getClientFactory().getGoodbyeView();
	}

	private GoodbyeView display;

	/**
	 * Invoked by the ActivityManager to start a new Activity
	 */
	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
		display.setName(name);
		display.getHelloLinkClickHandlers().addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				getPlaceController().goTo(new HelloPlace("Hello me"));

			}
		});
		getClientFactory().getMain().setMainPanel(display.asWidget());
	}

	/**
	 * Navigate to a new Place in the browser
	 */
	public void goTo(Place place) {
		getPlaceController().goTo(place);
	}

}
